<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>个人信息</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand" />  
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" href="layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="js/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" href="css/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="css/personal.css" media="all">
</head>
<body>
<section class="layui-larry-box">
	<div class="larry-personal">
		<header class="larry-personal-tit">
			<span>修改密码</span>
		</header><!-- /header -->
		<div class="larry-personal-body clearfix changepwd">
			<form class="layui-form "  action="">
				<div class="layui-form-item ">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-block">  
					  	<input type="text" name="userName"  id="userName"  class="layui-input layui-disabled" value="" disabled="disabled" >
					</div>
				</div>
			</form>
			<form class="layui-form " method="post" action="">
			 	
				<div class="layui-form-item">
					<label class="layui-form-label">旧密码</label>
					<div class="layui-input-block">  
					  	<input type="password" name="oldPwd" id="oldPwd"  autocomplete="off"  class="layui-input" value="" placeholder="请输入旧密码">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-block">  
					  	<input type="password" name="userPwd" id="userPwd"  autocomplete="off"  class="layui-input" value="" placeholder="请输入新密码">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认密码</label>
					<div class="layui-input-block">  
					  	<input type="password" name="" id="userPwds" autocomplete="off"  class="layui-input" value="" placeholder="请输入确认新密码">
					</div>
				</div>
				<div class="layui-form-item change-submit">
					<div class="layui-input-block">
						<div class="layui-btn" id="button_a" lay-submit="" lay-filter="demo1">立即提交</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</section>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/md5.js"></script>
<script>
	layui.use(['form','layer','util'],function(){
        var form = layui.form();
        var $ = layui.jquery,
       	layer = layui.layer,
     	util = layui.util;
		/**
		 * 使用内部工具组件
		 */
		util.fixbar();
		/**
		 ****************************jq扩展函数*******************************v**
		 */
		$.ajax({
			type: "get",
			url : url +'/ic-iot/users/'+adminId,
			dataType: 'json',
			beforeSend: function(request) {
            	request.setRequestHeader("accessToken", accessToken);
        	},
			success : function(data) {
				if(data['code'] == -3){
					layer.msg(data['description']);
					window.location.href = "login.html";
				}else if (data['code'] == -38){
					layer.msg(data['description']);
					window.location.href = "login.html";
				}else if (data['code'] == -39){
					layer.msg(data['description']);
					window.location.href = "login.html";
				}else if (data['code']!=1){
					layer.msg(data['description']);
				}else{
					$("#userName").val(data.result.userName);
				}
				
			}
		});
		
		
		$("#button_a").on('click',function(){
			var oldPwd = hex_md5($("#oldPwd").val()); 
        	var userPwd = hex_md5($("#userPwd").val()); 
        	console.log(userPwd);
			$.ajax({
				url : url +'/ic-iot/users/'+adminId+'/pwd',
				type : 'POST',
				dataType : 'json',
				data :{
					"oldPwd":oldPwd,
					"userPwd":userPwd,
				},
				beforeSend: function(request) {
		            request.setRequestHeader("accessToken", accessToken);
		        },
				success : function(data) {
					if(data['code'] == 1){
						layer.msg(data['description']);
					}else{
						ifajax(data);
					}
				}
			});
		})
	});
</script>
</body>
</html>